package com.jhy.suixianglu.daima20221221;

import java.util.HashSet;

public class Intersection {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> set = new HashSet<>();
        HashSet<Integer> reset = new HashSet<>();
        for (int num : nums1) {
            set.add(num);
        }
        for (int num :
                nums2) {
            if (set.contains(num)) {
                reset.add(num);
            }
        }

        int[] ints = new int[reset.size()];
        int index = 0;
        for (int num:reset
             ) {
            ints[index++] = num;
        }
        return  ints;
//        return  reset.stream().mapToInt(i->i).toArray();
    }
}
